package com.jy.appmarket.cards;

import it.gmariotti.cardslib.library.internal.Card;

import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jy.appmarket.R;
import com.jy.appmarket.activity.CardPageActivity;

/**
 * 类说明：
 * 
 * @author Baker.li
 * @date 2015年8月21日
 * @version 1.0
 */

public class AppDetailTagsUICard extends Card {
	private List<String> mTags;

	public AppDetailTagsUICard(Context context, List<String> tags) {
		super(context, R.layout.appdetail_tags_card_layout);
		if (tags.size() > 4) {
			mTags = tags.subList(0, 4);
		} else {
			mTags = tags;
		}
	}

	@Override
	public void setupInnerViewElements(ViewGroup parent, View view) {
		TextView tv[] = new TextView[] {parent.findViewById(R.id.appdetail_tags_tag1),
                parent.findViewById(R.id.appdetail_tags_tag2),
                parent.findViewById(R.id.appdetail_tags_tag3),
                parent.findViewById(R.id.appdetail_tags_tag4)};
		for (int i = 0; i < tv.length; i++) {
			if (i >= mTags.size()) {
				tv[i].setVisibility(View.INVISIBLE);
				continue;
			}
			final String tag = mTags.get(i);
			tv[i].setVisibility(View.VISIBLE);
			tv[i].setText(tag);
			tv[i].setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View v) {
					Intent it = new Intent(getContext(), CardPageActivity.class);
					it.putExtra(CardPageActivity.EXTRA_PATH, "tag");
					it.putExtra(CardPageActivity.EXTRA_TITLE, tag);
					Bundle bundle = new Bundle();
					bundle.putString("tagName", tag);
					it.putExtra(CardPageActivity.EXTRA_PARAMS, bundle);
					getContext().startActivity(it);
				}
			});
		}

		// for (final String tag : mTags) {
		// View v = li.inflate(R.layout.app_tag_item, parent, false);
		// TextView tv = (TextView) v.findViewById(R.id.app_tag_item_title);
		// tv.setOnClickListener(new View.OnClickListener() {
		// @Override
		// public void onClick(View v) {
		// Intent it = new Intent(getContext(), CardPageActivity.class);
		// it.putExtra(CardPageActivity.EXTRA_PATH, "tag");
		// it.putExtra(CardPageActivity.EXTRA_TITLE, tag);
		// Bundle bundle = new Bundle();
		// bundle.putString("tagName", tag);
		// it.putExtra(CardPageActivity.EXTRA_PARAMS, bundle);
		// getContext().startActivity(it);
		// }
		// });
		// tv.setText(tag);
		// fl.addView(v);
		// }

	}

	@Override
	public int getType() {
		return 6;
	}
	
	@Override
	public int getMarginTop(){
		return 0; //返回0，则在顶部没有空隙
	}
}